home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 460_01 / YACL0160.ZIP / uidemo / hit_test / appwin.cxx next >
Encoding:
C/C++ Source or Header  |  1996-02-29  |  2.0 KB  |  83 lines

  1.  
  2.  
  3.  
  4. #include "ui/lineseg.h"
  5. #include "ui/piewedge.h"
  6. #include "ui/chord.h"
  7. #include "ui/arc.h"
  8. #include "ui/ellipse.h"
  9. #include "ui/dsplsurf.h"
  10. #include "ui/label.h"
  11.  
  12. #include "appwin.h"
  13.  
  14.  
  15. AppWindow::AppWindow()
  16. : UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (50, 50, 500, 300))
  17. {
  18.     Title() = "YACL hit-testing demo";
  19.     _status = new UI_Label (this, UI_Rectangle (10, 10, 400, 30));
  20.     _status->Title() = "Click anywhere";
  21.     _graphics.Add (new UI_LineSegment (UI_Point (150, 50), 3.0, 70));
  22.     _graphics.Add (new UI_Chord (UI_Rectangle (300, 80, 100, 200), 30*64,
  23.                                  100*64));
  24.     _graphics.Add (new UI_PieWedge (UI_Rectangle (150, 150, 100, 200), 30*64,
  25.                                     120*64));
  26.     _graphics.Add (new UI_Ellipse   (100, 50, UI_Point (70, 80)));
  27.     _graphics.Add (new UI_Rectangle (200, 50, 40, 40));
  28. }
  29.  
  30. AppWindow::~AppWindow()
  31. {
  32.     _graphics.DestroyContents();
  33. }
  34.  
  35.  
  36. void AppWindow::Initialize ()
  37. {
  38.     _bgColor = UIColor_White; 
  39. }
  40.  
  41.  
  42. bool AppWindow::Paint (const UI_Rectangle&)
  43. {
  44.     UI_DisplaySurface& sfc = CreateDisplaySurface ();
  45.     short n = _graphics.Size();
  46.     for (short i = 0; i < n; i++)
  47.         ((UI_GraphicObject*) _graphics[i])->DrawOn (sfc, UI_Point(0,0));
  48.     DestroyDisplaySurface ();
  49.     return TRUE;
  50. }
  51.  
  52.  
  53. bool AppWindow::ButtonDown (const UI_Point& p, UI_MouseButton m,
  54.                             bool, bool)
  55. {
  56.     if (m != UIM_Left)
  57.         return FALSE;
  58.     short n = _graphics.Size();
  59.     UI_HitTest result;
  60.     for (short i = 0; i < n; i++) {
  61.         result = ((UI_GraphicObject*) _graphics[i])->HitTest (p);
  62.         if (result != UIHit_Outside)
  63.             break;
  64.     }
  65.     switch (result) {
  66.     case UIHit_Boundary:
  67.         _status->Title() = "On boundary of " +
  68.             CL_String (_graphics[i]->ClassName());
  69.         break;
  70.  
  71.     case UIHit_Inside:
  72.         _status->Title() = "Inside " + CL_String (_graphics[i]->ClassName());
  73.         break;
  74.         
  75.     case UIHit_Outside:
  76.         _status->Title() = "Outside";
  77.         break;
  78.     }
  79.     return TRUE;
  80. }
  81.  
  82.  
  83.